package com.quectel.core.module.patrol.service.impl;


import com.quectel.core.module.patrol.dao.VideoPatrolEventReportDao;
import com.quectel.core.module.patrol.dto.VideoPatrolEventReportDto;
import com.quectel.core.module.patrol.entity.VideoPatrolEventReportEntity;
import com.quectel.core.module.patrol.service.VideoPatrolEventReportService;
import com.quectel.core.module.patrol.service.VideoPatrolTaskService;
import com.quectel.util.common.CopyUtils;
import com.quectel.util.kit.Snowflake;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author caolu
 * @email louis.cao@quectel.com
 * @date 2020-07-07 15:47:11
 */
@DubboService
public class VideoPatrolEventReportServiceImpl implements VideoPatrolEventReportService {

    private static final Logger LOGGER = LoggerFactory.getLogger(VideoPatrolEventReportServiceImpl.class);

    @Autowired
    private VideoPatrolEventReportDao videoPatrolEventReportDao;
    @Autowired
    private VideoPatrolEventReportService reportService;
    @Autowired
    private VideoPatrolTaskService videoPatrolTaskService;


    /**
     * 新增上报
     * 更新任务状态
     *
     * @param eventReportDto
     */
    @Override
    public void report(VideoPatrolEventReportDto eventReportDto) {

        reportService.save(eventReportDto);

    }

    @Override
    public List<VideoPatrolEventReportDto> queryList(Map<String, Object> params) {
        List<VideoPatrolEventReportEntity> list = videoPatrolEventReportDao.queryList(params);
        return CopyUtils.copyList(list, VideoPatrolEventReportDto.class);
    }

    @Override
    public int queryTotal(Map<String, Object> params) {
        return videoPatrolEventReportDao.queryTotal(params);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long save(VideoPatrolEventReportDto dto) {
        VideoPatrolEventReportEntity entity = CopyUtils.copyObj(dto, VideoPatrolEventReportEntity.class);
        entity.setId(Snowflake.nextId());
        videoPatrolEventReportDao.insert(entity);
        return entity.getId();
    }

    @Override
    public void updateById(VideoPatrolEventReportDto dto) {
        VideoPatrolEventReportEntity entity = CopyUtils.copyObj(dto, VideoPatrolEventReportEntity.class);
        videoPatrolEventReportDao.updateById(entity);
    }

    @Override
    public VideoPatrolEventReportDto selectById(Long id) {
        VideoPatrolEventReportEntity entity = videoPatrolEventReportDao.selectById(id);
        return CopyUtils.copyObj(entity, VideoPatrolEventReportDto.class);
    }

    @Override
    public void deleteById(Long id) {
        videoPatrolEventReportDao.deleteById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteBatch(Long[] ids) {
        for (Long id : ids) {
            deleteById(id);
        }
    }
}
